package com.heima.account.action;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * @Author WSJ
 * @Date 2022-03-08-15:51
 * @Version 1.0 （版本号）
 */
@LocalTCC
public interface AccountAction {
    /**
     * 锁定资源Try
     * @param userId
     * @param money
     */
    @TwoPhaseBusinessAction(name = "deduct",commitMethod = "confirm",rollbackMethod = "cancel")
    void deduct(@BusinessActionContextParameter(paramName = "userId") Integer userId,
                @BusinessActionContextParameter(paramName = "money") Integer money);

    /**
     * 提交Confirm
     * @param context
     * @return
     */
    boolean confirm(BusinessActionContext context);


    /**
     * 失败回滚Cancel
     * @param context
     * @return
     */
    boolean cancel(BusinessActionContext context);
}
